﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jzy.Core.Common;
using Jzy.Core.Utility;
using ECommerce.Model.Member;

namespace ECommerce.DAL.Member
{
    public class MemberBaseDAL : BaseDAL
    {
        public void Startup(List<int> lstMemberIDs)
        {
            string memberIDs = ConvertUtil.ConvertToDbStr(lstMemberIDs);
            string sql = "update MemberBase set State=" + (int)MemberState.启用 + "where id in (" + memberIDs + ")";
            dbOper.RunSql(sql);
        }

        public void Stop(List<int> lstMemberIDs)
        {
            string memberIDs = ConvertUtil.ConvertToDbStr(lstMemberIDs);
            string sql = "update MemberBase set State=" + (int)MemberState.停用 + "where id in (" + memberIDs + ")";
            dbOper.RunSql(sql);
        }

        public MemberBaseInfo GetInfoByLoginName(string loginName)
        {
            string sql = "select * from MemberBase where LoginName=@p0";
            List<MemberBaseInfo> list = dbOper.Query<MemberBaseInfo>(sql, loginName);
            if (list.Count != 0)
            {
                return list.First();
            }
            else
            {
                return null;
            }
        }

        public void UpdateRemain(double remain, int memberID)
        {
            string sql = "update MemberBase with(updlock) set Remain=@p0 where ID=@p1";
            dbOper.RunSql(sql, remain, memberID);
        }

        public double GetRemain(int memberID)
        {
            string sql = "select Remain  from MemberBase with(xlock) where ID=@p0";
            double remain = dbOper.GetScalar<double>(sql, memberID);
            return remain;
        }
    }

}
